﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using RenAi.Medical.Model;

namespace RenAi.Medical.DAL
{
    public class HospitalBasicDAL
    {

        /// <summary>
        ///获取医院所有信息总行数
        /// </summary>
        /// <returns></returns>
        public int Getcount()
        {
            int i = Convert.ToInt32(DBhelper.Scalar("select COUNT(*) from HospitalBasic"));
            return i;
        }
        /// <summary>
        /// 显示医院基本所有信息(编号，名称，时间，电话，路径，简介)
        /// </summary>
        /// <param name="PagerIndex"></param>
        /// <param name="PagerSize"></param>
        /// <returns></returns>
        public DataTable GetHospitalBasicAll()
        {
            //string str = string.Format("select top {0} *from (select ROW_NUMBER ()over (order by HB_Id ASC)nid,* from HospitalBasic )AS TEMP WHERE nid>{1}", PagerSize, (PagerIndex - 1) * PagerSize);int PagerIndex,int PagerSize
            string str = "select * from HospitalBasic";
            return DBhelper.GetTable(str);
        }
        /// <summary>
        /// 添加医院基本信息
        /// </summary>
        /// <param name="h"></param>
        /// <returns></returns>
        public int AddHosp(HospitalBasic h)
        { 
            int i = DBhelper.NonQuery(string .Format ("insert into HospitalBasic (HB_Name,HB_Time,HB_Phone,HB_URL,HB_intro) values('{0}','{1}','{2}','{3}','{4}')",h.HB_Name,h.HB_Time,h.HB_Phone,h.HB_URL,h.HB_intro));
            return i;        
        }
        /// <summary>
        /// 根据医院编号删除医院基本信息
        /// </summary>
        /// <param name="HB_Id"></param>
        /// <returns></returns>
        public int DeleteHospitalBasic(string HB_Id)
        {
            int i = DBhelper.NonQuery(string.Format("delete from HospitalBasic where HB_Id={0}",HB_Id));
            return i;
        }
        /// <summary>
        /// 根据医院编号找到医院基本信息
        /// </summary>
        /// <param name="HB_Id"></param>
        /// <returns></returns>
        public DataTable GetHospitalBasic(string HB_Id)
        {
            DataTable dt = DBhelper.GetTable(string.Format("select *from HospitalBasic WHERE HB_Id ='{0}'", HB_Id));
            return dt;
        }
        /// <summary>
        /// 修改医院基本信息
        /// </summary>
        /// <param name="hosp"></param>
        /// <returns></returns>
        public int UptHospitalBasic(HospitalBasic hosp)
        {
            int i = DBhelper.NonQuery(string.Format("update HospitalBasic set HB_Name='{0}',HB_Time='{1}',HB_Phone='{2}',HB_URL='{3}',HB_intro='{4}' where HB_Id='{5}'", hosp.HB_Name, hosp.HB_Time, hosp.HB_Phone, hosp.HB_URL, hosp.HB_intro,hosp.HB_Id));
            return i;
        }
        /// <summary>
        /// 根据医院名称进行查询
        /// </summary>
        /// <param name="HB_Name"></param>
        /// <returns></returns>
        public DataTable SearchHospitalBasic(string HB_Name)
        {
            string sql = string.Format("select * from HospitalBasic where HB_Name  like '%{0}%'", HB_Name);
            return DBhelper.GetTable(sql);        
        }
    }
}
